﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using MailChimp4Umbraco.Businesslogic.ChimpAPI;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace MailChimp4Umbraco.Tests
{
    
    [TestClass]
    public class MailChimpResponseTests
    {
        [TestMethod]
        public void MailChimpResponse_TestXmlParserBoolean_ExpectSuccess()
        {
            string responseExample = "<MCAPI type=\"boolean\">1</MCAPI>";

            MailChimpResponse response = new MailChimpResponse(responseExample);
            
            Assert.IsNotNull(response);
            Assert.AreEqual(true, response.IsSuccess);
            Assert.AreEqual(String.Empty, response.MailChimpErrorMessage);
            Assert.AreEqual(0, response.ErrorCode);

        }

        [TestMethod]
        public void MailChimpResponse_TestXmlParserArray_ExpectError()
        {
            string responseExample = "<MCAPI type=\"array\"><error type=\"string\">thomas@mediaworkers.dk is already subscribed to list Mediaworkers Nyhedsbrev</error><code type=\"integer\">214</code></MCAPI>";

            MailChimpResponse response = new MailChimpResponse(responseExample);

            Assert.IsNotNull(response);
            Assert.AreEqual(false, response.IsSuccess);
            Assert.AreEqual("thomas@mediaworkers.dk is already subscribed to list Mediaworkers Nyhedsbrev", response.MailChimpErrorMessage);
            Assert.AreEqual(214, response.ErrorCode);
        }


        [TestMethod]
        public void MailChimpResponse_TestXmlParserEmpty_ExpectError()
        {
            string responseExample = string.Empty;

            MailChimpResponse response = new MailChimpResponse(responseExample);

            Assert.IsNotNull(response);
            Assert.AreEqual(false, response.IsSuccess);
            Assert.AreEqual(0, response.ErrorCode);
        }

    }
}
